let app = getApp()
Page({
    /**
     * 页面的初始数据
     */
    data: {
        userInfo: "",
        configColor: app.globalData.configColor,
        showTheme: false,
        checkedDefault: false,
        checkedFense: false,
        checkedFenZi: false,
        statusBarHeight: app.globalData.statusBarHeight,
        navBarHeight: app.globalData.navBarHeight,
        showRemarkFocus: false,
        remarkFocus0: false,
        remarkFocus500: false,
        remarkFocus800: false,
        remarkFocus1000: false,
    },
    toggle(event) {
        let index = event.currentTarget.dataset.index
        if (index == 0) {
            this.setData({
                checkedDefault: true,
                checkedFense: false,
                checkedFenZi: false,
            });
        }
        if (index == 1) {
            this.setData({
                checkedDefault: false,
                checkedFense: true,
                checkedFenZi: false,
            });
        }
        if (index == 2) {
            this.setData({
                checkedDefault: false,
                checkedFense: false,
                checkedFenZi: true,
            });
        }
        if (wx.getStorageSync("userInfo").theme != index) {
            wx.request({
                url: app.globalData.url + '/updateTheme',
                method: 'POST',
                header: {
                    'content-type': 'application/json'
                },
                data: {
                    id: wx.getStorageSync('userInfo').id,
                    theme: index
                },
                success: (res) => {
                    let responseData = res.data
                    if (responseData.flag) {
                        let userInfo = wx.getStorageSync('userInfo');
                        userInfo.theme = index
                        wx.setStorageSync('userInfo', userInfo);
                        this.setData({
                            showTheme: false
                        });
                        app.chooseTheme(index)
                        if (wx.getStorageSync('configColor') !== this.data.configColor) {
                            this.setData({ configColor: wx.getStorageSync('configColor') });
                        }
                    } else {
                        wx.showModal({
                            icon: 'none',
                            title: '修改失败'
                        })
                    }
                },
                fail: (err) => {
                    console.log("失败", err);
                }
            })
        }

    },
    toggleRemarkFocus(event) {
        let index = event.currentTarget.dataset.index
        if (index == 0) {
            this.setData({
                remarkFocus0: true,
                remarkFocus500: false,
                remarkFocus800: false,
                remarkFocus1000: false,
            });
        }
        if (index == 1) {
            this.setData({
                remarkFocus0: false,
                remarkFocus500: true,
                remarkFocus800: false,
                remarkFocus1000: false,
            });
        }
        if (index == 2) {
            this.setData({
                remarkFocus0: false,
                remarkFocus500: false,
                remarkFocus800: true,
                remarkFocus1000: false,
            });
        }
        if (index == 3) {
            this.setData({
                remarkFocus0: false,
                remarkFocus500: false,
                remarkFocus800: false,
                remarkFocus1000: true,
            });
        }
        if (wx.getStorageSync("userInfo").focusTime != index) {
            wx.request({
                url: app.globalData.url + '/updateFocusTime',
                method: 'POST',
                header: {
                    'content-type': 'application/json'
                },
                data: {
                    id: wx.getStorageSync('userInfo').id,
                    focusTime: index
                },
                success: (res) => {
                    let responseData = res.data
                    if (responseData.flag) {
                        let userInfo = wx.getStorageSync('userInfo');
                        userInfo.focusTime = index
                        wx.setStorageSync('userInfo', userInfo);
                        this.setData({
                            showTheme: false
                        });
                    } else {
                        wx.showModal({
                            icon: 'none',
                            title: '修改失败'
                        })
                    }
                }
            })
        }

    },
    onClose() {
        this.setData({
            showTheme: false,
            showRemarkFocus: false
        })
    },
    showTheme() {
        if (this.selectComponent('#loginPopup').init()) {
            return
        }
        this.setData({
            showTheme: true
        })
    },
    showRemarkFocus() {
        if (this.selectComponent('#loginPopup').init()) {
            return
        }
        this.setData({
            showRemarkFocus: true
        })
    },
    go_personal() {
        if (this.selectComponent('#loginPopup').init()) {
            return
        }
        wx.navigateTo({
            url: "/pages/personal/personal",
        });
    },
    go_category() {
        if (this.selectComponent('#loginPopup').init()) {
            return
        }
        wx.navigateTo({
            url: "/pages/category/category",
        });
    },
    go_car() {
        if (this.selectComponent('#loginPopup').init()) {
            return
        }
        wx.navigateTo({
            url: "/pages/car/car",
        });
    },
    // 退出登录
    cancle_allow() {
        if (this.selectComponent('#loginPopup').init()) {
            return
        }
        wx.showModal({
            title: '退出登录',
            content: '确定退出?',
            complete: (res) => {
                if (res.cancel) {
                }
                if (res.confirm) {
                    app.chooseTheme(0)
                    wx.removeStorageSync('userInfo')
                    wx.reLaunch({
                        url: '/pages/my/my'
                    });
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        // 登录弹窗
        if (this.selectComponent('#loginPopup').init()) {
            this.setData({
                userInfo: {
                    name: "未登录",
                    avatar: "/images/未登录.jpg"
                }
            });
            return
        }
        if (wx.getStorageSync('configColor') !== this.data.configColor) {
            this.setData({ configColor: wx.getStorageSync('configColor') });
        }
        this.setData({
            userInfo: wx.getStorageSync("userInfo"),
        });
        if (wx.getStorageSync("userInfo").theme == 0) {
            this.setData({
                checkedDefault: true,
                checkedFense: false,
                checkedFenZi: false,
            });
        }
        if (wx.getStorageSync("userInfo").theme == 1) {
            this.setData({
                checkedDefault: false,
                checkedFense: true,
                checkedFenZi: false,
            });
        }
        if (wx.getStorageSync("userInfo").theme == 2) {
            this.setData({
                checkedDefault: false,
                checkedFense: false,
                checkedFenZi: true,
            });
        }
        if (wx.getStorageSync("userInfo").focusTime == 0) {
            this.setData({
                remarkFocus0: true,
                remarkFocus500: false,
                remarkFocus800: false,
                remarkFocus1000: false,
            });
        }
        if (wx.getStorageSync("userInfo").focusTime == 1) {
            this.setData({
                remarkFocus0: false,
                remarkFocus500: true,
                remarkFocus800: false,
                remarkFocus1000: false,
            });
        }
        if (wx.getStorageSync("userInfo").focusTime == 2) {
            this.setData({
                remarkFocus0: false,
                remarkFocus500: false,
                remarkFocus800: true,
                remarkFocus1000: false,
            });
        }
        if (wx.getStorageSync("userInfo").focusTime == 3) {
            this.setData({
                remarkFocus0: false,
                remarkFocus500: false,
                remarkFocus800: false,
                remarkFocus1000: true,
            });
        }
    },

    /**
    * 生命周期函数--监听页面加载
    */
    onLoad(options) {
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady() { },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() { },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() { },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() { },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() { },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() { },

});